/*
package cn.chenxinjie.hrm.service.impl;

import cn.chenxinjie.hrm.constant.CourseTypeConstant;
import cn.chenxinjie.hrm.domain.CourseType;
import cn.chenxinjie.hrm.mapper.CourseTypeMapper;
import cn.chenxinjie.hrm.service.ICourseTypeService;
import cn.chenxinjie.hrm.util.AjaxResult;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

*/
/**
 * 课程目录 服务实现类
 *
 * @author chenxinjie
 * @since 2022-03-12
 *//*

@Service
public class CourseTypeServiceImpl extends ServiceImpl<CourseTypeMapper, CourseType> implements ICourseTypeService {

    @Autowired
    private CourseTypeMapper courseTypeMapper;

    @Override
    @Cacheable(cacheNames = CourseTypeConstant.COURSE_TYPE_TREE_DATA,key = "'key'")
    public AjaxResult treeData() {
        List<CourseType> list = loadTreeData();
        // 通过sql封装数据
        //List<CourseType> list = courseTypeMapper.treeData();
        return AjaxResult.me().setResultObj(list);
    }

    private List<CourseType> loadTreeData() {
        ArrayList<CourseType> result = new ArrayList<>();
        List<CourseType> types = courseTypeMapper.selectList(null);
        // 组装关系 子级的pid等于父级的id
        HashMap<Long, CourseType> map = new HashMap<>();
        types.stream().forEach(type -> {
            map.put(type.getId(),type);
        });
        types.stream().forEach(type -> {
            // 如果type的pid为0 说明是第一层级
            if (type.getPid() == 0) {
                result.add(type);
            }else{
                CourseType parent = map.get(type.getPid());
                parent.getChildren().add(type);
            }
        });
        return result;
    }

    @Override
    public boolean insert(CourseType entity) {
        return super.insert(entity);
    }

    @Override
    public boolean updateById(CourseType entity) {
        return super.updateById(entity);
    }

    @Override
    @CacheEvict(cacheNames = CourseTypeConstant.COURSE_TYPE_TREE_DATA,key = "'key'")
    public boolean deleteById(Serializable id) {
        return super.deleteById(id);
    }
}
*/
